import 'package:flutter/material.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/widgets/load_image.dart';

class ClickItem extends StatelessWidget {
  const ClickItem(
      {Key? key,
      this.onTap,
      required this.title,
      this.content = "",
      this.textAlign = TextAlign.start,
      this.titleStyle = const TextStyle(color: Colours.text_dark, fontSize: 16),
      this.contentStyle,
      this.maxLines = 1})
      : super(key: key);

  final GestureTapCallback? onTap;
  final String title;
  final String content;
  final TextAlign textAlign;
  final TextStyle titleStyle;
  final TextStyle? contentStyle;
  final int maxLines;

  @override
  Widget build(BuildContext context) {
    String _title = title != null ? title : '';
    String _content = content != null ? content : '';
    return InkWell(
      onTap: onTap,
      child: Container(
        margin: const EdgeInsets.only(left: 15.0),
        padding: const EdgeInsets.fromLTRB(0, 15.0, 15.0, 15.0),
        constraints:
            BoxConstraints(maxHeight: double.infinity, minHeight: 50.0),
        width: double.infinity,
        decoration: BoxDecoration(
            border: Border(
          bottom:
              Divider.createBorderSide(context, color: Colours.line, width: 1),
        )),
        child: Row(
          //为了数字类文字居中
          crossAxisAlignment: maxLines == 1
              ? CrossAxisAlignment.center
              : CrossAxisAlignment.start,
          children: <Widget>[
            Text(
              _title,
              style: titleStyle,
            ),
            const Spacer(),
            Expanded(
              flex: 4,
              child: Padding(
                padding: const EdgeInsets.only(right: 8.0, left: 16.0),
                child: Text(
                  _content,
                  maxLines: maxLines,
                  textAlign: maxLines == 1 ? TextAlign.right : textAlign,
                  overflow: TextOverflow.ellipsis,
                  style: contentStyle ??
                      TextStyle(color: Colours.text_gray, fontSize: 14),
                ),
              ),
            ),
            Opacity(
              // 无点击事件时，隐藏箭头图标
              opacity: onTap == null ? 0 : 1,
              child: Padding(
                padding: EdgeInsets.only(top: maxLines == 1 ? 0.0 : 2.0),
                child: LoadAssetImage(
                  'ic_arrow_right',
                  width: 20,
                  height: 20,
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}
